// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import Router from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(Router)
router.beforeEach(function (to, from, next) {
  if (localStorage.getItem('data')) {
    store.commit('SET_TOKEN')
    if ((to.path === '/login' || to.path === '/adminLogin' || to.path === '/register' || to.path === '/')) {
       next(store.state.user)
    } else {
     next()
    }
  } else if (to.path === '/login'|| to.path === '/adminLogin'|| to.path === '/register' ) {
  next()
  } else {
  next('/login')
   }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
